import 'package:flutter/material.dart';
import 'package:flutter_ahj_app/base/utils/JUIKit/JText.dart';
import 'package:flutter_ahj_app/base/values/dimens.dart';

typedef callBack = Function(int index);

class ContentListView extends StatefulWidget {
  final List leadingList;

  ///左边图片
  final List titleList;

  ///显示的 title
  final List data;

  /// 传过来的数据
  final callBack onTap;
  final bool isShowTrailing;

  ///是否 显示 右边 →

  const ContentListView(
      {Key key,
      this.leadingList,
      this.titleList,
      this.data,
      this.onTap,
      this.isShowTrailing = true})
      : super(key: key);

  @override
  _ContentListViewState createState() => _ContentListViewState();
}

class _ContentListViewState extends State<ContentListView> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: ListView.separated(
        shrinkWrap: true,
        padding: EdgeInsets.only(top: 0),
        physics: const NeverScrollableScrollPhysics(),
        itemCount: widget.titleList.length,
        //列表项构造器
        itemBuilder: (BuildContext context, int index) {
          return ListTile(
            leading: widget.leadingList == null
                ? null
                : Icon(widget.leadingList[index]),
            //Image.asset(widget.leadingList[index]),
            title: _title(index),
            trailing: widget.isShowTrailing == true
                ? Icon(Icons.chevron_right)
                : null,
            onTap: () => widget.onTap(index),
          );
        },
        //分割器构造器
        separatorBuilder: (BuildContext context, int index) {
          return Divider(
            color: Color(0xffe4e4e4),
            indent: 15,
            height: 1,
          );
        },
      ),
    );
  }

  _title(int index) {
    return widget.titleList[index] == "我的推广海报"
        ? Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              JText(
                widget.titleList[index],
                fontSize: Dimens.textSize28,
              ),
              JText(
                widget.data == null
                    ? " "
                    : widget.data.length > 0
                        ? widget.data[index]
                        : " ",
                color: Colors.grey,
                fontSize: Dimens.textSize24,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              )
            ],
          )
        : Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              JText(
                widget.titleList[index],
                fontSize: Dimens.textSize28,
              ),
              Expanded(
                child: JText(
                
                  widget.data == null
                      ? " "
                      : widget.data.length > 0
                          ? widget.data[index]
                          : " ",
                  color: Colors.grey,
                  fontSize: Dimens.textSize24,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  textAlign: TextAlign.end,
                ),
              )
            ],
          );
  }
}
